{%extends 'base_admin.html'%}

{%block content%}

<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">车辆搜索-权限取消记录</h3>
  </div>
  <div class="panel-body">
    <a class="btn btn-default" href="/car/index" style="float: left;">
       <span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> 
        返回车辆管理
    </a>
    <form method="get" class="form-inline" style="float: right;" >
        <!-- {%csrf_token%} -->
        <label for="">
        </label>
        <div class="form-group">
            <input type="text" class="form-control"  placeholder="姓名" name="name" value="{{name}}">
        </div>
        <div class="form-group">
            <input type="text" class="form-control"  placeholder="车牌号" name="car_no" value="{{car_no}}">
        </div>
        <select class="form-control" name="category" value="{{category}}">
            {%if category == "1"%}
              <option value="" >—— 人员类别 ——</option>
              <option value="1" selected>本校职工</option>
              <option value="2">外聘老师</option>
              <option value="3">合作单位</option>
            {%elif category == "2"%}
              <option value="">—— 人员类别 ——</option>
              <option value="1" >本校职工</option>
              <option value="2" selected>外聘老师</option>
              <option value="3">合作单位</option>
            {%elif category == "3"%}
              <option value="">—— 人员类别 ——</option>
              <option value="1" >本校职工</option>
              <option value="2">外聘老师</option>
              <option value="3" selected>合作单位</option>
            {%else%}
              <option value="">—— 人员类别 ——</option>
              <option value="1">本校职工</option>
              <option value="2">外聘老师</option>
              <option value="3">合作单位</option>
            {%endif%}
        </select>
        
        <button type="submit" class="btn btn-default">搜索</button>
        <a class="btn btn-default" href="/car/cancel_car_list">重置</a>
    </form>
  </div>
</div>

<table class="table table-striped">
    <thead>
        <tr>
            <td>序号</td>
            <td class="">姓名</td>
            <td class="">部门</td>
            <td class="">所在单位</td>
            <td class="">车牌号</td>
            <td class="">电话号码</td>
            <td class="">权限取消日期</td>
            <td class="">人员类别</td>
            <td class="">取消原因</td>
            <td class="">操作</td>
        </tr>
    </thead>
    <tbody>
            {% for queryset in queryset %}
                <tr>
                    <td class="info_id">{{forloop.counter0|add:page_id_start}}</td>
                    <td>{{queryset.name}}</td>
                    <!-- 通过get_字段名_display方法找到对应choices -->
                    <td>{{queryset.department}}</td>
                    <!-- 获得college对象，通过get_字段名_display方法找到对应choices -->
                    <td>{{queryset.dep_detail}}</td>
                    <td>{{queryset.car_number}}</td>
                    <td>{{queryset.phone_number}}</td>
                    <td class="due_date">{{queryset.cancel_date|date:"Y-m-d"}}</td>
                    <td>{{queryset.get_category_display}}</td>
                    <td>{{queryset.get_reason_display}}</td>
                    <td style="display: flex;flex-direction: row;">
                        <a class="btn btn-primary btn-xs" href="/car/{{queryset.id}}/cancel_edit" style="margin-right: 10px;">恢复权限</a>
                        <a class="cancel btn btn-danger btn-xs" data-id="{{queryset.id}}">删除</a>
                    </td>
                </tr>
            {% endfor %}
    </tbody>
    {{queryset.name}}
</table>


<nav  aria-label="Page navigation" style="float: left;">
  <ul class="pagination">
      {{page_info}}
  </ul>
</nav>
<div style="float:right;margin-top: 30px;">
    {{page_str}}
</div>

{%endblock%}

{%block script%}
    <script>
        $('.cancel').click(function(){
            var nid = $(this).data("id")
            confirmYes = confirm('请确认删除,删除后将无法恢复');
            if (confirmYes){
                $.ajax({
                        url:"/car/" + nid + "/cancel_delete",
                        type:"GET",
                        dataType:"JSON",
                        success:function(response){
                            if(response.status){
                                alert("删除成功");
                                window.location.reload()
                            }else{
                                alert("删除失败，请重试")
                            }

                        },
                        error:function(xhr,status,error){
                            console.error('AJAX请求错误:',error);
                            alert("发生错误，请稍后再试");

                        },
                    });
            };
        });
    </script>

{%endblock%}